package fr.alma.domo.music.rc;

import java.util.ArrayList;
import java.util.List;

import fr.alma.domo.model.AbstractService;
import fr.alma.domo.model.Property;

@SuppressWarnings("serial")
public class Player extends AbstractService{
	private static long _ID = 0;	
	public final long id = _ID++;
	
	@Property(type=List.class)
	public static final String SONG_LIST = "Player#songs";

	/**
	 * Le titre du son en cour d'exécution
	 */
	@Property(type=String.class)
	public final static String PLAYING_TITLE = "Player#playing";

	public Player(){
		super("Player");
		setAttribute(SONG_LIST,new ArrayList<String>());
		setAttribute(PLAYING_TITLE,"");
	}
	
	public void addSong(String song){
		List<String> songs = getSongList();
		if(song!=null && !songs.contains(song)){
			songs.add(song);
		}
	}
	
	public void removeSong(String song){
		if(song!=null){
			getSongList().remove(song);
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getSongList(){
		return (List<String>)getAttribute(SONG_LIST,List.class);
	}

	public void setPlayingTitle(String title){
		this.setAttribute(PLAYING_TITLE,title);
	}
	
	public String getPlayingTitle(){
		return this.getAttribute(PLAYING_TITLE, String.class);
	}
	
	@Override
	public String toString(){
		return "Player"+id;		
	}
	
	@Override
	public boolean equals(Object o){
		if(o!=null && o instanceof Player){
			return id==((Player)o).id;
		}
		return false;
	}
	
}
